package com.sinven.controller;

import com.sinven.common.Pager;
import com.sinven.pojo.Article;
import com.sinven.pojo.Category;
import com.sinven.service.ArticleService;
import com.sinven.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("culture")
public class CultureController {

    @Autowired
    private ArticleService articleService;
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("{code}")
    public String showNews(Model model, @PathVariable("code")String code,
                           @RequestParam(value = "page",defaultValue = "1")Long page){
        Pager<Article> pager = articleService.queryArticles(code, page);
        model.addAttribute("pager",pager);
        return "culture/"+code;
    }

    @RequestMapping({"{code}/{id}"})
    public String showDetail(Model model,
                             @PathVariable("code") String code,
                             @PathVariable("id")Long id){
        Category category = categoryService.queryCategoryByCode(code);
        model.addAttribute("category",category);
        Article article = articleService.queryArticle(id);
        model.addAttribute("article",article);
        return "detail";
    }
//    public String showActivity(Model model){
//
//    }
}
